<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Messenger/classes/PhpFox_ComponentAlertList.class.php, $Author:  $ */



/** Crush alert list component
 * 
 * @package module.messenger
 * @version $Id: PhpFox_ComponentAlertList.class.php 143 2008-01-07 05:17:38Z phpfoxsv $
 *   PHPFox Team ()
 */
class PhpFox_Mod_Messenger_ComponentAlertList extends BaseComponent
{
    /** Processing method
     */
	function process()
	{
	    $oReq = &App::getRequest();
	    /* @var $oReq Request */

        $oSrvMessenger = &$this->_oModule->getService('Messenger');
        $aCond = array();
        $oUrl = &App::getUrl();
        $sUser = $oReq->get('user') ? $oReq->get('user') : false;
        
	    if($oReq->get('sbm'))
        {
            if($oReq->get('user_name'))
                $oUrl->setParam('user', $oReq->get('user_name'));
            else
                $oUrl->setParam('user');
            App::forward($oUrl->getUrl());
        }
        
        $aCond = $sUser ? array('to'=>' = "'.$sUser.'"') : array();
        
		$iPage = $oReq->getInt('page', 1);
    	$iPageSize = App::getParam('admin.pagesize');
    	$aCond['type'] = '="crush"';
       	$aArg = App::getParam('seen');
	    list($aAlerts, $iTotal) = $oSrvMessenger->getAlertList($aCond, $iPage, $iPageSize, 'time DESC');
	    foreach ($aAlerts as $i=>$aAlert)
	    {
            $aAlerts[$i]['text'] = str_replace(chr(10), '<br>', $aAlert['text']);
            $aAlerts[$i]['seen'] = (empty($aAlert['seen'])) ? 'Unseen' : ($aAlert['seen'] == $aArg['viewed'] ? 'Viewed' : 'Guessed');
	    }
         		    
	    $oPager = App::newObject('Pager', $iTotal, $iPage, $iPageSize);        
	    
        $oTpl = &$this->_oModule->getTemplate();

        
        $oTpl->assignSrc(array(
			                    'aAlerts'    => $aAlerts,
			                    'sUser'      => $sUser,
                                'bEmpty'     => empty($aAlerts) ? true : false,
			                    'aPaging'    => $oPager->getInfo($oUrl),
		));
		$srcHtml = $oTpl->fetch('AlertList.html');
		return $srcHtml;
	}
}
?>